<template>
	<view>
		<web-view :src="realUrl" v-if="realUrl"></web-view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				loadUrl: "",
				realUrl: "",
				webAuth: null,
			}
		},
		onLoad(options) {
			uni.hideShareMenu({
				menus: ['shareAppMessage', 'shareTimeline']
			})
			this.loadUrl = decodeURIComponent(options.url)
		},
		onShow: function() {
			this.showPage()
		},
		methods: {
			showPage() {
				const plugin = requirePlugin("shop2cn-shopapis-plugin");
				const currentToken = plugin.getAccessToken()
				if (this.webAuth === currentToken) {
					// 特殊逻辑：企点客服过渡页面，则不再触发onshow机制
					if (this.realUrl && this.realUrl.indexOf('/qidian?') >= 0) {
						return;
					}
					const url = plugin.createWebViewUrl({
						url: this.loadUrl,
						ylpage: {}
					}) + `#showpage${new Date().getTime()}`;
					this.realUrl = url
					return;
				}
				this.webAuth = currentToken;
				const url = plugin.createWebViewUrl({
					url: this.loadUrl,
					ylpage: {}
				}) + '#initpage';
				if (!this.realUrl) {
					this.realUrl = url
				} else {
					this.realUrl = ''
					setTimeout(() => {
						this.realUrl = ''
					}, 100)
				}
			},
		}
	}
</script>

<style>
</style>